<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>文件压缩解压 | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="文件压缩解压">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/System/%E6%96%87%E4%BB%B6%E5%8E%8B%E7%BC%A9%E8%A7%A3%E5%8E%8B.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="文件压缩解压">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/System/%E6%96%87%E4%BB%B6%E5%8E%8B%E7%BC%A9%E8%A7%A3%E5%8E%8B.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="文件压缩解压">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/72.7ff0ab11.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link router-link-active">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link router-link-active">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>System</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/System/" aria-current="page" class="sidebar-link">System</a></li><li><a href="/System/CentOS.html" class="sidebar-link">CentOS</a></li><li><a href="/System/Docker.html" class="sidebar-link">Docker</a></li><li><a href="/System/Linux操作.html" class="sidebar-link">Linux操作</a></li><li><a href="/System/Linux配置.html" class="sidebar-link">Linux配置</a></li><li><a href="/System/内网穿透.html" class="sidebar-link">内网穿透</a></li><li><a href="/System/挂载网盘.html" class="sidebar-link">挂载网盘</a></li><li><a href="/System/文件压缩解压.html" class="active sidebar-link">文件压缩解压</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/System/文件压缩解压.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/System/文件压缩解压.html#tar" class="sidebar-link">tar</a></li><li class="sidebar-sub-header"><a href="/System/文件压缩解压.html#bzip2" class="sidebar-link">BZip2</a></li><li class="sidebar-sub-header"><a href="/System/文件压缩解压.html#lzma2" class="sidebar-link">LZMA2</a></li><li class="sidebar-sub-header"><a href="/System/文件压缩解压.html#deflate" class="sidebar-link">Deflate</a></li></ul></li><li><a href="/System/邮箱.html" class="sidebar-link">邮箱</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="文件压缩解压"><a href="#文件压缩解压" class="header-anchor">#</a> 文件压缩解压</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#tar">tar</a></li><li><a href="#bzip2">BZip2</a></li><li><a href="#lzma2">LZMA2</a><ul><li><a href="#_7zip">7zip</a></li></ul></li><li><a href="#deflate">Deflate</a><ul><li><a href="#gzip">gzip</a></li><li><a href="#zlib">zlib</a></li><li><a href="#zip">zip</a></li><li><a href="#unzip">unzip</a></li></ul></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <blockquote><p>rar tar zip 7z 是归档容器，里面可以放多个文件、有目录结构，其中 tar本身不带压缩</p></blockquote> <blockquote><p>rar 带单独的压缩算法（据说类 Deflate），加密算法（AES），有相对完善的压缩过滤器</p></blockquote> <blockquote><p>zip 压缩算法Deflate，因为历史问题被迫成为多算法的加密容器（互不兼容的 AES），压缩比相对不太高，
不识别文件名的编码，有特殊的带过滤格式 zipx。gz是zip算法的一个GNU实现。</p></blockquote> <blockquote><p>7-zip 压缩算法 LZMA、LZMA2、ppmd、bzip2，加密算法（AES），有初步的过滤能力</p></blockquote> <blockquote><p>tar 可以和压缩或加密格式串用，tar.gz tar.bzip2 tar.xz tar.lzma 都是常见的压缩格式组合压缩算法方面，
对常规文件现在 7z 自带的 lzma2 是最佳选择，对多媒体文件，可考虑 rar 和 zipx</p></blockquote> <blockquote><p>xz的默认压缩级别是6。7z的默认压缩级别是5，至少在字典大小上相当于xz的压缩级别7，另外7z默认开了多线程，有多核可用的时候表现会好些</p></blockquote> <blockquote><p>xz和7z的默认参数压缩算法都是lzma2（tar能解压7z，7-zip也能解压xz），这个算法出自7-zip作者<code>Igor Pavlov</code>。</p></blockquote> <ul><li><a href="https://sourceforge.net/projects/getgnuwin32" target="_blank" rel="noopener noreferrer">https://sourceforge.net/projects/getgnuwin32<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://github.com/google/zopfli" target="_blank" rel="noopener noreferrer">https://github.com/google/zopfli<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="tar"><a href="#tar" class="header-anchor">#</a> tar</h2> <blockquote><p><code>tar</code>是在<code>Linux</code>中使用得非常广泛的文档打包格式（保留 unix 风格的文件权限）。它只消耗非常少的CPU以及时间去打包文件，
但它仅仅只是一个打包工具，并不负责压缩。</p></blockquote> <blockquote><p>实际使用中，除了要打包之外，往往还需要其他的压缩命令一起出现进行一下压缩，提高空间利用率。</p></blockquote> <p><strong>参数</strong></p> <ul><li><p>命令类型参数：</p> <ol><li><code>-c</code>或<code>–create</code>：建立新的备份文件。</li> <li><code>-x</code>或<code>–extract</code>或<code>–get</code>：从备份文件中还原文件。</li></ol></li> <li><p>压缩方式参数：</p> <ol><li><code>-j</code>或<code>–bzip2</code>：以bz2的算法来压缩或者解压文件。</li> <li><code>-z</code>或<code>–gzip</code>或<code>–ungzip</code>：通过 gzip 指令处理备份文件。</li></ol></li> <li><p>其他常用参数：</p> <ol><li><code>-v</code>或<code>–verbose</code>：显示指令执行过程。</li> <li><code>-C &lt;目的目录&gt;</code>或<code>–directory=&lt;目的目录&gt;</code>：切换到指定的目录。</li></ol></li></ul> <p><strong>压缩</strong></p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 将目标打包成一个*.tar格式的文件</span>
<span class="token function">tar</span> -cvf 名称.tar 目录或文件

<span class="token comment"># 将目标打包成一个*.tgz格式的文件</span>
<span class="token function">tar</span> -czvf 名称.tgz 目录或文件

<span class="token comment"># 将目标打包并压缩成一个*.tar.gz格式的文件</span>
<span class="token function">tar</span> -czvf 名称.tar.gz 目录或文件

<span class="token comment"># 将目标打包并压缩成一个*.tar.bz2格式的文件</span>
<span class="token function">tar</span> -cjvf 名称.tar.bz2 目录或文件

<span class="token comment"># 将打包好的tar文件压缩成一个*.tar.xz格式的文件				</span>
xz -z 名称.tar.xz
<span class="token comment"># 或者一条命令执行</span>
<span class="token function">tar</span> -Jcvf 文件名.tar.xz 目录或文件

<span class="token comment"># 将目标打包并压缩成一个*.tar.7z格式的文件</span>
<span class="token function">tar</span> cvf - 目录或文件 <span class="token operator">|</span> 7z a -si 文件名.tar.7z
</code></pre></div><blockquote><p>注意：在使用<code>tar</code>的<code>--exclude</code>命令排除打包时，末尾不能加<code>/</code>或者路径为绝对路径，否则还是会把排除目录以及其下的文件打包进去。</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 打包的时候我们要排除 tomcat/logs 目录，命令如下：</span>
<span class="token function">tar</span> -zcvf tomcat.tar.gz --exclude<span class="token operator">=</span>tomcat/logs tomcat

<span class="token comment"># 如果要排除多个目录，增加 --exclude 即可，如下命令排除logs和libs两个目录及文件xiaoshan.txt</span>
<span class="token function">tar</span> -zcvf tomcat.tar.gz --exclude<span class="token operator">=</span>tomcat/logs --exclude<span class="token operator">=</span>tomcat/libs --exclude<span class="token operator">=</span>tomcat/xiaoshan.txt tomcat
</code></pre></div><p><strong>解压</strong></p> <blockquote><p>参数<code>-C</code>解压到指定目录下</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 解压一个*.tar的文件包内容到当前目录下</span>
<span class="token function">tar</span> -xvf pakage_name.tar

<span class="token comment"># 解压一个*.tgz的文件包内容到当前目录下							</span>
<span class="token function">tar</span> -xzvf pakage_name.tgz

<span class="token comment"># 解压一个*.tar.gz的压缩包内容到当前目录下</span>
<span class="token function">tar</span> -xzvf pakage_name.tar.gz

<span class="token comment"># 解压一个*.tar.bz2的压缩包内容到当前目录下</span>
<span class="token function">tar</span> -xjvf pakage_name.tar.bz2

<span class="token comment"># tar.xz压缩包需要先解压为tar格式包</span>
xz -d pakage_name.tar.xz
<span class="token comment"># 再解开tar格式包到当前目录下</span>
<span class="token function">tar</span> -xvf pakage_name.tar
<span class="token comment"># 或者一条命令执行</span>
<span class="token function">tar</span> -Jxvf 文件名.tar.xz
</code></pre></div><h2 id="bzip2"><a href="#bzip2" class="header-anchor">#</a> BZip2</h2> <ul><li><a href="https://www.sourceware.org/bzip2" target="_blank" rel="noopener noreferrer">https://www.sourceware.org/bzip2<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="lzma2"><a href="#lzma2" class="header-anchor">#</a> LZMA2</h2> <ul><li><a href="https://tukaani.org/xz" target="_blank" rel="noopener noreferrer">https://tukaani.org/xz<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="_7zip"><a href="#_7zip" class="header-anchor">#</a> 7zip</h3> <ul><li><a href="https://sourceforge.net/projects/sevenzip" target="_blank" rel="noopener noreferrer">https://sourceforge.net/projects/sevenzip<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://www.7-zip.org" target="_blank" rel="noopener noreferrer">https://www.7-zip.org<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul> <blockquote><p>注意：所有的参数和值之间是没有空格的</p></blockquote> <p><strong>参数</strong></p> <ul><li><code>a</code> 添加文件或文件夹到压缩包。</li> <li><code>b</code> 基准</li> <li><code>d</code> 从存档中删除文件</li> <li><code>e</code> 从存档中提取文件（不使用目录名）</li> <li><code>h</code> 计算文件的哈希值</li> <li><code>i</code> 显示有关受支持格式的信息</li> <li><code>l</code> 列出档案内容</li> <li><code>rn</code> 重命名存档中的文件</li> <li><code>t</code> 测试档案的完整性</li> <li><code>u</code> 更新文件以存档</li> <li><code>x</code> 解压文件，保留原来的目录结构</li></ul> <ul><li><code>-t</code> 指定压缩类型，默认7z。</li> <li><code>-r</code> 表示递归所有的子文件夹。</li> <li><code>-mmt[N]</code> 设置CPU线程数</li> <li><code>-mx=值</code> 设置压缩级别：<code>-mx1</code>（最快），<code>-mx9</code>（最慢，压缩比最高），默认为5。</li> <li><code>-ao</code> 设置覆盖模式，<code>a</code>全部覆盖</li> <li><code>-o</code> 指定解压到的目录</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># CentOS安装7zip</span>
yum –y <span class="token function">install</span> p7zip

<span class="token comment"># 解压到当前目录下,不保留原来的目录结构</span>
7za e 文件名

<span class="token comment"># 解压到当前目录下,但保留原来的目录结构</span>
7za x 文件名

<span class="token comment"># 用7z压缩成tar</span>
7za a -ttar 文件名.tar 文件夹

<span class="token comment"># 用7z把tar压缩成gz</span>
7za a -tgzip 文件名.tar.gz 文件名.tar
</code></pre></div><h2 id="deflate"><a href="#deflate" class="header-anchor">#</a> Deflate</h2> <blockquote><p>在1990年左右，Info-ZIP组编写了可移植的，免费开源的实用程序zip和unzip实用程序，使用Deflate进行压缩以及对zip和早期格式进行解压缩</p></blockquote> <ul><li><a href="https://sourceforge.net/projects/infozip" target="_blank" rel="noopener noreferrer">https://sourceforge.net/projects/infozip<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="gzip"><a href="#gzip" class="header-anchor">#</a> gzip</h3> <blockquote><p>在90年代初期，gzip格式被开发为Unix compress实用程序的替代，它是从Info-ZIP实用程序中的Deflate代码衍生而来</p></blockquote> <ul><li><a href="https://www.gnu.org/software/gzip" target="_blank" rel="noopener noreferrer">https://www.gnu.org/software/gzip<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="zlib"><a href="#zlib" class="header-anchor">#</a> zlib</h3> <blockquote><p>zlib 是通用的压缩库，提供了一套 in-memory 压缩和解压函数，并能检测解压出来的数据的完整性(integrity)。zlib是从gzip代码改编而来</p></blockquote> <ul><li><a href="http://gailly.net" target="_blank" rel="noopener noreferrer">http://gailly.net<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://zlib.net" target="_blank" rel="noopener noreferrer">https://zlib.net<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/zlib-ng/zlib-ng" target="_blank" rel="noopener noreferrer">https://github.com/zlib-ng/zlib-ng<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://sourceforge.net/projects/libpng" target="_blank" rel="noopener noreferrer">https://sourceforge.net/projects/libpng<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="http://www.winimage.com/zLibDll" target="_blank" rel="noopener noreferrer">http://www.winimage.com/zLibDll<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="zip"><a href="#zip" class="header-anchor">#</a> zip</h3> <blockquote><p><code>zip</code>是压缩程序</p></blockquote> <p><strong>参数</strong></p> <ul><li><code>A</code> 调整可执行的自动解压缩文件。</li> <li><code>d</code> 从压缩文件内删除指定的文件。</li> <li><code>D</code> 压缩文件内不建立目录名称。</li> <li><code>F</code> 尝试修复已损坏的压缩文件。</li> <li><code>g</code> 将文件压缩后附加在既有的压缩文件之后，而非另行建立新的压缩文件。</li> <li><code>j</code> 只保存文件名称及其内容，而不存放任何目录名称。</li> <li><code>m</code> 将文件压缩并加入压缩文件后，删除原始文件，即把文件移到压缩文件中。</li> <li><code>o</code> 以压缩文件内拥有最新更改时间的文件为准，将压缩文件的更改时间设成和该文件相同。</li> <li><code>q</code> 不显示指令执行过程。</li> <li><code>r</code> 递归处理，将指定目录下的所有文件和子目录一并处理。</li> <li><code>S</code> 包含系统和隐藏文件。</li> <li><code>v</code> 显示指令执行过程或显示版本信息。</li> <li>&lt;压缩效率&gt; 压缩效率是一个介于 1-9 的数值。</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">zip</span> 文件名.zip 文件或目录
</code></pre></div><h3 id="unzip"><a href="#unzip" class="header-anchor">#</a> unzip</h3> <blockquote><p>unzip是解压程序。</p></blockquote> <p><strong>参数</strong></p> <ul><li><code>f</code> 更新现有的文件。</li> <li><code>l</code> 显示压缩文件内所包含的文件。</li> <li><code>v</code> 执行是时显示详细的信息。</li> <li><code>C</code> 压缩文件中的文件名称区分大小写。</li> <li><code>j</code> 不处理压缩文件中原有的目录路径。</li> <li><code>L</code> 将压缩文件中的全部文件名改为小写。</li> <li><code>n</code> 解压缩时不要覆盖原有的文件。</li> <li><code>o</code> 不必先询问用户，unzip 执行后覆盖原有文件。</li> <li><code>P&lt;密码&gt;</code> 使用 zip 的密码选项。</li> <li><code>q</code> 执行时不显示任何信息。</li> <li><code>[.zip 文件]</code> 指定.zip 压缩文件。</li> <li><code>[文件]</code> 指定要处理.zip 压缩文件中的哪些文件。</li> <li><code>d&lt;目录&gt;</code> 指定文件解压缩后所要存储的目录。</li> <li><code>x&lt;文件&gt;</code> 指定不要处理.zip 压缩文件中的哪些文件。</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">unzip</span> 文件名.zip
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//System/文件压缩解压.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020-07-26 09:43:54</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/System/挂载网盘.html" class="prev">
        挂载网盘
      </a></span> <span class="next"><a href="/System/邮箱.html">
        邮箱
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/72.7ff0ab11.js" defer></script>
  </body>
</html>
